<?
/*
 * Copyright 2004-2005 Sigve Indregard.
 *
 * This file is part of Laivsys.
 *
 * Laivsys is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Laivsys is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Laivsys; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * $Id: nettsvar.php 6 2005-07-11 23:14:47Z say $
 */
 
include_once("db.php");
include_once("laivid.php");
include_once("design.php");
include_once("normauth.php");

$arr=getLaiv();

$sidetittel=$arr['Tittel']." - Min side";
include("top.php");

$std_fields = array (	"Navn" => "Navn",
			"F�dselsdato" => "Fodselsdato",
			"Adresse" => "Adresse",
			"Postnr og sted" => "Postnrsted",
			"Epost" => "Epost",
			"Telefon" => "Telefon",
			"P�r�rende" => "Parorende",
			"P�r�rendes tlf" => "Parorende_tlf"
		);

if ($_REQUEST['editprocess'] == 'true') {
	//update the record
	$data=$_REQUEST['data'];
	$sql="UPDATE Deltakere SET ";
	foreach ($std_fields as $field)
		$sql .= "$field='".$data[$field]."', ";
	
	$sql = substr($sql, 0, strlen($sql) - 2);
	$sql .= " WHERE ID=".$_SESSION['UserID'];

	mysql_query($sql) or die(mysql_error());
}

function printDetails($fields, $record) {
	echo "<a href=\"nettsvar.php?change=true\">Rediger...</a>";
	echo "<table>";
	foreach ($fields as $description => $name) {
		?>
		<tr>
			<th><?=$description?></th>
			<td><?=$record[$name]?></td>
		</tr>
		<?
	}
	echo "</table>";
}

function printDetailsChangeable($fields, $record) {
	echo "<table>";
	echo "<form method=\"post\" action=\"nettsvar.php\">";
	echo "<input type=\"hidden\" name=\"editprocess\" value=\"true\">";
	foreach ($fields as $description => $name) {
		?>
		<tr>
			<th><?=$description?></th>
			<td><input name="data[<?=$name?>]" value="<?=$record[$name]?>"></td>
		</tr>
		<?
	}
	echo "<tr><td></td><td><input type=\"submit\" value=\"Lagre endringer\"></td></tr>";
	echo "</form></table>";
}

headline("Laiv");
text("<p>{$arr['Tittel']}</p>");
?>


<div class="headline">Personalia</div>
<div class="text">
<?
$sql="SELECT * FROM Deltakere WHERE ID=".$_SESSION['UserID'];
$rs=mysql_query($sql) or die(mysql_error());
if (!mysql_num_rows($rs)) 
	die("No such record!");
$user=mysql_fetch_assoc($rs);

if ($_REQUEST['change'] == 'true')
	printDetailsChangeable($std_fields, $user);
else 
	printDetails($std_fields, $user);

?>
</div>

<div class="headline">Rollespilldetaljer</div>
<div class="text">
<table>
<tr>
	<th>Erfaring</th>
	<td><?=$user['Erfaring']?></td>
</tr>
<tr>
	<th>Karakteristikker</th>
	<td><?
	$sql="SELECT Karakteristikk FROM Karakteristikklinje LEFT JOIN Karakteristikker ON Karakteristikklinje.KarakteristikkID=Karakteristikker.ID WHERE DeltakerID=".$_SESSION['UserID']." ORDER BY Karakteristikk";
	$stikker=mysql_query($sql) or die(mysql_error());
	while ($stikk=mysql_fetch_row($stikker)) 
		echo $stikk[0]."<br>";
	?>
	</td>
</tr>
<tr>
	<th>Egenskaper</th>
	<td><?
	$sql="SELECT Egenskap FROM Egenskaplinje LEFT JOIN Egenskaper ON Egenskaplinje.EgenskapID=Egenskaper.ID WHERE DeltakerID=".$_SESSION['UserID']." ORDER BY Egenskap";
	$stikker=mysql_query($sql);
	while ($stikk=mysql_fetch_row($stikker)) 
		echo $stikk[0]."<br>";
	?>
	</td>
</tr>
</table>
</div>

<div class="headline">Tilbakemelding</div>
<div class="text">
<?
switch ($user['Godkjent']) {
case -1:
	$string="Det er dessverre ikke funnet plass til deg i denne laiven. S�k igjen en annen gang, eller p� en <a href='http://laiv.org'>annen laiv</a>.";
	$more=false;
	break;
case 0:
	$string="Du er ikke vurdert enda.";
	$more=false;
	break;
case 1:
	$string="Din s�knad er innvilget. Velkommen p� laiv!";
	$more=true;
	break;
}
echo $string;
?>
</div>
<?
if ($more) {
	$sql="SELECT * FROM r_Rolle WHERE eierID=".$user['ID'];
	$roller=mysql_query($sql);
	if (mysql_num_rows($roller)) {
		?>
		<div class="headline">Rollebeskrivelse</div>
		<div class="text">
		Du er tildelt en rolle! Les rollebeskrivelsen godt, og husk � ikke r�pe noe til noen.<p>Rollebeskrivelsen din finner du <a href="rollebeskrivelse.php">her</a>.</p>
		</div>
		<?
	}
		
	$sql="SELECT dokumenter.ID, beskrivelse, str FROM dok_tilganger LEFT JOIN dokumenter ON dok_tilganger.dokID=dokumenter.ID WHERE deltakerID=".$user['ID'];
	$doks=mysql_query($sql) or die(mysql_error());
	?>
	<div class="headline">Dokumenter, kompendier mv.</div>
	<div class="text">
	<?
	if (mysql_num_rows($doks)) {
		?>
		<table border=1>
		<?
		while ($dok=mysql_fetch_assoc($doks)) {
			?>
			<tr>
			<td><?=$dok['beskrivelse']?></td>
			<td><?=round($dok['str']/1024, 2)?> kB</td>
			<td><a href="nettsvar_lastned.php?id=<?=$dok['ID']?>">Last ned</a></td>
			</tr>
			<?
		}
		echo "</table>";
	} else {
		echo "<i>Ingen dokumenter til deg enn�...</i>";
	}
	?>
	</div>
	<?
}
include "bottom.php" ;
?>
